package com.atao.example.newdate02;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * @author 阿涛
 * @date 2021-03-07
 */
public class Test {
    public static void main(String[] args) {
        //todo 16:25:46.448（纳秒值）
        LocalTime todayTimeWithMillisTime = LocalTime.now();

        //todo 16:28:48 不带纳秒值
        LocalTime todayTimeWithNoMillisTime = LocalTime.now().withNano(0);
        LocalTime time1 = LocalTime.parse("23:59:59");


        //todo 转化为时间戳 毫秒值
        long time = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
        long time2 = System.currentTimeMillis();

        //todo 时间戳转化为localdatetime
        DateTimeFormatter df = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss.SSS");
        System.out.println(df.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.of("Asia/Shanghai"))));


    }
}
